﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Server
{
    public partial class ServerForm : Form
    {
        ServerModel model;
        OpenFileDialog openFileDialog;
        public delegate void DelegateSetLabel(string information); 

        public ServerForm()
        {
            InitializeComponent();
        }

        private void ServerForm_Load(object sender, EventArgs e)
        {
            openFileDialog = new OpenFileDialog();
        }

        public void setLabel(string information)
        {
            if (this.label.InvokeRequired)
            {
                DelegateSetLabel d = new DelegateSetLabel(setLabel);
                this.Invoke(d, new object[] { information });
            }
            else
            {
                this.label.Text = information;
            }
            
        }

        private void open_Button_Click(object sender, EventArgs e)
        {
            openFileDialog.Title = "选择PPT文件";
            openFileDialog.Filter = "Power Point 演示文稿(*.ppt)|*.ppt*";
            openFileDialog.CheckFileExists = true;
            openFileDialog.CheckPathExists = true;
            openFileDialog.ValidateNames = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {

                filePathTextBox.Text = openFileDialog.FileName;
                open_Button.Text = "重新选择";
                if (model != null)
                {
                    model.close();
                    model = null;
                }
                model = new ServerModel(this);
                model.initialization(openFileDialog.FileName);
                model.startBluetooth();
            }
        }

        private void ServerForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (model != null)
            {
                model.close();
                model = null;
            }
        }
    }
}
